Convert a non-negative integer num
to its English words representation.
Input: num = 123 Output: "One Hundred Twenty Three"
Input: num = 12345 Output: "Twelve Thousand Three Hundred Forty Five"
Input: num = 1234567 Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
0 <= num <= 231 - 1
classSolution: defnumberToWords(self, num: int) ->str: ifnum==0: return"Zero"billion=num//1000000000million=num%1000000000//1000000thousand=num%1000000//1000lt1000=num%1000ret= [] ifbillion>0: ret.append(self.numberToWordsLT1000(billion) +" Billion") ifmillion>0: ret.append(self.numberToWordsLT1000(million) +" Million") ifthousand>0: ret.append(self.numberToWordsLT1000(thousand) +" Thousand") iflt1000>0: ret.append(self.numberToWordsLT1000(lt1000)) return' '.join(ret) defnumberToWordsLT1000(self, num: int) ->str: lt20= [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", ] tens= [ "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety", ] hundred=num//100ten=num%100//10unit=num%10ret= [] ifhundred>0: ret.append(lt20[hundred] +" Hundred") iften>1: ret.append(tens[ten]) iften==1: ret.append(lt20[10+unit]) elifunit>0: ret.append(lt20[unit]) return' '.join(ret)